//
//  MMTableViewCell.m
//  ZZLC
//
//  Created by 杨春至 on 2017/12/16.
//  Copyright © 2017年 ZhongZeng. All rights reserved.
//

#import "MMTableViewCell.h"
#import "CircleProgress.h"

@interface MMTableViewCell ()

@property (nonatomic,strong) UILabel *NoLb;

@property (nonatomic,strong) UILabel *typeLb;

@property (nonatomic,strong) UILabel *numLb;

@property (nonatomic,strong) UILabel *profitLb;

@property (nonatomic,strong) UILabel *desLb;

@property (nonatomic,strong) UILabel *DayAndMoneyLb;

@property (nonatomic,strong) UILabel *restCoutnLb;

@property (nonatomic,strong) UIView *lineView;

@property (nonatomic,strong) CircleProgress *circleView;

@property (nonatomic,strong) UIImageView *rewardImageView;

@property (nonatomic,strong) UILabel *rewardLb;

@end

@implementation MMTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self configUI];
    }
    return self;
}
- (void)setModel:(ProDetailModel *)model{
    _model = model;
    _NoLb.text = _model.title;
    if (_model.activity.length==0) {
        _typeLb.hidden = YES;
    }else{
        _typeLb.hidden = NO;
    }
    _typeLb.text = [NSString stringWithFormat:@"%@     ",_model.activity];
    [_typeLb sizeToFit];
    _typeLb.textAlignment = NSTextAlignmentCenter;
//    if (_typeLb.text.length<1) {
//      _typeLb.hidden = YES;
//    }
    _profitLb.text = [NSString stringWithFormat:@"%@%@",_model.baseEarnings ,@"%"];
    _DayAndMoneyLb.text = [NSString stringWithFormat:@"%@天|%ld元",_model.lcqx,[_model.atleastMoney integerValue]/100];
    _restCoutnLb.text = [NSString stringWithFormat:@"剩余金额%.2f万元",[_model.leftCopies floatValue]/10000];
    NSLog(@"%f",floor(([_model.wcjd floatValue]*100)/100));

    [self setCProgress:[_model.wcjd doubleValue]];
    _rewardLb.text = [NSString stringWithFormat:@"+%@ %@",model.jiangLiEarnings,@"%"];
    if ([model.jiangLiEarnings floatValue]<=0) {
        _rewardImageView.hidden = YES;
    }else{
        _rewardImageView.hidden = NO;
    }
    
}
- (void)configUI{
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    UIView *contentView = self.contentView;
    [contentView addSubview:self.NoLb];
    [contentView addSubview:self.typeLb];
    [contentView addSubview:self.profitLb];
    [contentView addSubview:self.desLb];
    [contentView addSubview:self.DayAndMoneyLb];
    [contentView addSubview:self.restCoutnLb];
    [contentView addSubview:self.lineView];
    [contentView addSubview:self.circleView];
    [self sendSubviewToBack:_lineView];
    [contentView addSubview:self.rewardImageView];
    [self.rewardImageView addSubview:self.rewardLb];
}
- (void)setCProgress:(CGFloat)Cprogress{
    if (Cprogress >= 1) {
        _circleView.progress = -1;
        _circleView.desLb.text = @"售罄";
        _circleView.desLb.textColor = RGBCOLOR(160, 160, 160);
        _profitLb.textColor = RGBCOLOR(160, 160, 160);
    }else if (Cprogress <= 0) {
        _circleView.progress = -1;
        _circleView.desLb.text = @"起售";
//        _circleView.desLb.textColor = RGBCOLOR(160, 160, 160);
        _profitLb.textColor = ZZGoldColor;
    }else{
        _circleView.progress = Cprogress;
        _profitLb.textColor = ZZGoldColor;
    }
}
- (void)layoutSubviews{
    CGFloat gap = 15;
    [_NoLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(gap));
        make.top.equalTo(self);
        make.height.equalTo(@(109/2));
        make.width.equalTo(@(170));
    }];
    [_typeLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(-gap);
        make.centerY.equalTo(_NoLb);
        make.height.equalTo(@23);
//        make.width.equalTo(@(80));
    }];
    [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self);
        make.bottom.equalTo(_NoLb.mas_bottom);
        make.height.equalTo(@0.4);
        make.right.equalTo(self);
    }];

    [_profitLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(gap));
        make.top.equalTo(_lineView.mas_bottom).offset(gap);
        make.width.equalTo(_NoLb);
        make.height.equalTo(@20);
    }];
    [_desLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(gap));
        make.top.equalTo(_profitLb.mas_bottom).offset(gap);
        make.width.equalTo(_NoLb);
        make.height.equalTo(@13);
    }];
   
    [_DayAndMoneyLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_profitLb.mas_right).offset(KWidth <= 320?-3*gap:gap);
        make.centerY.equalTo(_profitLb.mas_centerY);
        make.width.equalTo(_NoLb);
        make.height.equalTo(@15);
    }];
    [_restCoutnLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_DayAndMoneyLb);
        make.centerY.equalTo(_desLb.mas_centerY);
        make.width.equalTo(_NoLb);
        make.height.equalTo(@13);
    }];
    [_circleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-gap));
        make.size.mas_equalTo(CGSizeMake(40, 40));
        make.top.equalTo(_DayAndMoneyLb);
    }];
    [_rewardImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(55));
        make.bottom.equalTo(_profitLb.mas_centerY);
        make.height.equalTo(@(45.0/2));
        make.width.equalTo(@(40));
    }];
    [_rewardLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(-7, 0, 0, 0));
    }];
}
- (UILabel *)NoLb{
    if (!_NoLb) {
        _NoLb = [UILabel new];
        _NoLb.font = [UIFont systemFontOfSize:14];
        _NoLb.textColor = [UIColor blackColor];
//        _NoLb.text = @"新手专享 No.1132";
    }
    return _NoLb;
}
- (UILabel *)typeLb{
    if (!_typeLb) {
        _typeLb = [UILabel new];
        _typeLb.font = [UIFont systemFontOfSize:13];
        _typeLb.textColor = [UIColor whiteColor];
        _typeLb.backgroundColor = RGBCOLOR(253, 205, 90);
        _typeLb.clipsToBounds = YES;
        _typeLb.textAlignment = NSTextAlignmentCenter;
        _typeLb.layer.cornerRadius = 23.0/2;
//        _typeLb.text = @"新手专享";
    }
    return _typeLb;
}

- (UILabel *)profitLb{
    if (!_profitLb) {
        _profitLb = [UILabel new];
        _profitLb.font = [UIFont systemFontOfSize:21];
        _profitLb.textColor = ZZGoldColor;
//        _profitLb.text = @"15.00%";
    }
    return _profitLb;
}
- (UILabel *)desLb{
    if (!_desLb) {
        _desLb = [UILabel new];
        _desLb.font = [UIFont systemFontOfSize:14];
        _desLb.textColor = [UIColor grayColor];
        _desLb.text = @"预期年变化收益";
    }
    return _desLb;
}
- (UILabel *)DayAndMoneyLb{
    if (!_DayAndMoneyLb) {
        _DayAndMoneyLb = [UILabel new];
        _DayAndMoneyLb.font = [UIFont systemFontOfSize:14];
        _DayAndMoneyLb.textColor = [UIColor blackColor];
//        _DayAndMoneyLb.text = @"15天 | 100元";
    }
    return _DayAndMoneyLb;
}
- (UILabel *)restCoutnLb{
    if (!_restCoutnLb) {
        _restCoutnLb = [UILabel new];
        _restCoutnLb.font = [UIFont systemFontOfSize:13];
        _restCoutnLb.textColor = [UIColor grayColor];
//        _restCoutnLb.text = @"剩余金额33.88万元";
    }
    return _restCoutnLb;
}
- (UIView *)lineView{
    if (!_lineView) {
        _lineView = [UIView new];
        _lineView.backgroundColor = [UIColor qmui_colorWithHexString:@"#dfdfdf"];
    }
    return _lineView;
}
- (CircleProgress *)circleView{
    if (!_circleView) {
        _circleView = [[CircleProgress alloc]initWithFrame:CGRectMake(0, 0, 40, 40) lineWidth:3 LineColor:RGBCOLOR(245, 245, 245) fillColor:RGBCOLOR(253, 205, 90) andPercent:0.2];
//        _circleView.backgroundColor = [UIColor blackColor];
    }
    return _circleView;
}
- (UIImageView *)rewardImageView{
    if (!_rewardImageView) {
        _rewardImageView = [UIImageView new];
        _rewardImageView.image = UIImageMake(@"reword");
    }
    return _rewardImageView;
}
- (UILabel *)rewardLb{
    if (!_rewardLb) {
        _rewardLb = [UILabel new];
        _rewardLb.textColor = [UIColor whiteColor];
        _rewardLb.font = [UIFont systemFontOfSize:10];
        _rewardLb.textAlignment = NSTextAlignmentCenter;
    }
    return _rewardLb;
}

@end
